import $ from "jquery";
$.ajaxSetup({
  async: false,
  dataType: "JSON",
});

/* @return <Promise> resolve 返回的数据 */
function post(url, data) {
  return new Promise((resolve, reject) => {
    $.ajax({
      url,
      data,
      type: "post",
      success: data => {
        resolve(data);
      },
      error: (xhr, errCode) => {
        reject("请求错误:" + errCode);
      },
    });
  });
}

export default {
  searchBeauticianOrders({
    fid,
    state,
    rows,
    page
  }) {
    return post(g.ctx + "/order/searchBeauticianOrders", {
      fid,
      state,
      rows,
      page
    });
  },
  fillUserRemarks({
    fid,
    uid,
    remarks,
    specials
  }) {
    return post(g.ctx + "/order/fillUserRemarks", {
      fid,
      uid,
      remarks,
      specials
    });
  },
  dayReports({
    fid
  }) {
    return post(g.ctx + "/report/dayReports", {
      fid
    });
  },
  monthReports({
    fid
  }) {
    return post(g.ctx + "/report/monthReports", {
      fid
    });
  },
  upReport({
    rids
  }) {
    return post(g.ctx + "/report/upReport", {
      rids
    });
  },
  searchStocks({
    fid,
    rows,
    page
  }) {
    return post(g.ctx + "/stock/searchStocks", {
      fid,
      rows,
      page
    });
  },
  searchStaffStocks({
    pid,
    fid,
    rows,
    page
  }) {
    return post(g.ctx + "/stock/searchStaffStocks", {
      pid,
      fid,
      rows,
      page
    });
  },
  userHomeInfo({
    uid
  }) {
    return post(g.ctx + "/home/homeInfo", {
      uid
    });
  },
  getStoreItems({
    sid
  }) {
    return post(g.ctx + "/common/storeItems", {
      sid
    });
  },
  getProCities() {
    return post(g.ctx + "/common/getProCities", {});
  },
  completeOrder({
    oid
  }) {
    return post(g.ctx + "/order/completeOrder", {
      oid
    })
  },
  loadUserRemarks() {
    return post(g.ctx + "/order/loadUserRemarks")
  },
};